﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Linq;

namespace TRIG_MOD_STATUSSUMMARY.DocTypeStatusSummaryCNT
{
    public partial class DocTypeStatusSummaryCNTUserControl : UserControl
    {
        DataForStatusSummary objCls = new DataForStatusSummary();

        List<string> docTypes = new List<string>();
        List<string> discipAbb = new List<string>();

        public List<string> DocTypes
        {
            get { return docTypes; }
            set { docTypes = value; }
        }

        public List<string> Disciplines
        {
            get { return discipAbb; }
            set { discipAbb = value; }
        }

        //RadioButtonList rdDates = new RadioButtonList();

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                docTypes = objCls.GetDocumentType(ddlDocsTypes);
                discipAbb = objCls.GetDiscipiline();
                ddlDocsTypes.Items.Add("Inspection Requests");
                DateValidation();

            }
            catch (Exception x)
            {

                errorMessage.Text += x.Message;
            }

            
        }

        private void DateValidation()
        {
            stDate.MaxDate = DateTime.Today;
            endDate.MaxDate = DateTime.Today;
            stSumGrid.DataSource = null;
            stSumGrid.Visible = false;
            if (Convert.ToInt32(rdDates.SelectedItem.Value) == 0)
            {
                endDate.Visible = false;
                stDate.IsRequiredField = true;
                stDate.SelectedDate = DateTime.Today;
            }
            else
            {
                endDate.Visible = true;
                stDate.IsRequiredField = true;
                endDate.IsRequiredField = true;
            }
        }

        protected void btnProcess_Click(object sender, EventArgs e)
        {

            NullLabels();
            objCls.rdDates = rdDates;
            if (Convert.ToInt32(rdDates.SelectedItem.Value) == 1) // As of Today
                GetDates();
            else
                GetDates("Today");
            objCls.grid = stSumGrid;

            //objCls.GridCSS(stSumGrid);
            objCls.CreateTable("contractor");
            objCls.Group = ("CNT");
            int ck = objCls.GetDocItemsbyDiscipiline_DSS(ddlDocsTypes.SelectedItem.Text, Disciplines, errorMessage, "DSS");
            if (ck > 0)
            {
                objCls.BindGrid(stSumGrid, lbl_R1, lbl_R2, lbl_R3, lbl_R4, lbl_R5, "DSS");
                if (stSumGrid.Rows.Count > 1)
                {
                    string p = "% of MSs ";
                    lblr1.Text = "Under Review" + p;
                    lblr2.Text = "Approved (Code : 1) as per total submitted" + p;
                    lblr3.Text = "Approved as noted (Code : 2) as per total submitted" + p;
                    lblr4.Text = "Not Approved (Code : 3) as per total submitted" + p;
                    lblr5.Text = "Superseded as per total submitted" + p;
                }
                else { lblr1.Text = ""; lblr2.Text = ""; lblr3.Text = ""; lblr4.Text = ""; lblr5.Text = ""; lbl_R1.Text = ""; lbl_R2.Text = ""; lbl_R3.Text = ""; lbl_R4.Text = ""; lbl_R5.Text = ""; }
            }
            else { }

            //if (objCls.ckItemsInDocs("METHOD STATEMENTS (FLOW IS DIFFERENT, DESCRIBED LATER)") > 0)
            //{
            //    objCls.GetDocItemsbyDiscipiline("METHOD STATEMENTS (FLOW IS DIFFERENT, DESCRIBED LATER)", Disciplines, errorMessage, "contractor");
            //}

        }

        private void NullLabels()
        {
            lblr1.Text = ""; lblr2.Text = ""; lblr3.Text = ""; lblr4.Text = ""; lblr5.Text = ""; lbl_R1.Text = ""; lbl_R2.Text = ""; lbl_R3.Text = ""; lbl_R4.Text = ""; lbl_R5.Text = "";
            errorMessage.Text = "";
            stSumGrid.Visible = true;
        }

        private void GetDates(string today)
        {
            string startDt = Convert.ToString(stDate.SelectedDate.ToShortDateString());
            objCls.cpStDT = startDt;
            objCls.cpEndDT = startDt;

        }

        private void GetDates()
        {
            //stDT.IsRequiredField = true;
            //endDT.IsRequiredField = true;
            string startDt = Convert.ToString(stDate.SelectedDate.ToShortDateString());
            string endDt = Convert.ToString(endDate.SelectedDate.ToShortDateString());
            objCls.cpStDT = startDt;
            objCls.cpEndDT = endDt;

        }

        protected void SelectedIndexChanged(object sender, EventArgs e)
        {
            stDate.ClearSelection();
            endDate.ClearSelection();
            stSumGrid.DataSource = null;
            stSumGrid.Visible = false;
            lblr1.Text = ""; lblr2.Text = ""; lblr3.Text = ""; lblr4.Text = ""; lblr5.Text = ""; lbl_R1.Text = ""; lbl_R2.Text = ""; lbl_R3.Text = ""; lbl_R4.Text = ""; lbl_R5.Text = "";
            errorMessage.Text = "";
        }
       
       
    }
}
